package com.example.log.alarm.agent;

import com.example.log.alarm.advice.exeception.ThrowableAdviceInterceptor;
import com.example.log.alarm.constant.InterceptorType;
import com.example.log.alarm.manager.ErrorLogManager;
import com.example.log.alarm.repository.MemoryRepository;
import com.example.log.alarm.spy.BootstrapQueuedSpy;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: spring-agent
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2023-05-06 17:47
 **/
public class Main {

    public static void main(String[] args) throws ClassNotFoundException, InterruptedException {

        for (int i = 0; i < 1000000000; i++) {
            new String("AgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBaseAgentVisitBase" + i).intern();
        }
    }

    public static void agentVisitBase() throws ClassNotFoundException, InterruptedException {
        List<AgentVisitBase> visits = new ArrayList<>();
        AgentVisitBase visitBase = new AgentVisitBase(Throwable.class.getName(),
                ThrowableAdviceInterceptor.class, InterceptorType.CONSTRUCTOR);
        visits.add(visitBase);
        String spyClass = BootstrapQueuedSpy.class.getName();
        AgentTemplate agentTemplate = new AgentTemplate(visits, spyClass);
        agentTemplate.start();

        MemoryRepository repository = new MemoryRepository();
        ErrorLogManager logManager = new ErrorLogManager(repository, null);
        logManager.start();
        try {
            throw new RuntimeException("123!");
        } catch (Exception e) {

        }

        Thread.sleep(6000);
    }

}
